<?php
// ----------------------------------------------------------------------
// pn-commerce Shopping Cart Solution for PostNuke
// http://pncommerce.de
// http://www.sourceforge.net/projects/pn-commerce/
//
// It is based on PostKart 0.701QA from
//			Destin LeBlanc [ postkart@zenflesh.com ]
// ----------------------------------------------------------------------
// Source file:  $Source: /cvsroot/pn-commerce/pn-commerce/pnpmotherapi.php,v $
//
// Last changes from:  $Author: landseer $
//
// Revision:           $Revision: 1.26 $
//
// Date of revision    $Date: 2004/09/12 15:17:32 $
//  
// ----------------------------------------------------------------------
// LICENSE
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License (GPL)
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// To read the license please visit http://www.gnu.org/copyleft/gpl.html
// ----------------------------------------------------------------------

require_once("modules/pncommerce/common.php");

/**
 * load the config array and return it
 * no arguments needed
 */
function pncommerce_pmotherapi_getConfig ($args=array())
{
  $data=pnModGetVar ('pncommerce', 'pmotherData');
  if(isset($data)) return unserialize($data);
  else return false;
}

/**
 * save the config array
 * @param $args array of config values
 */
function pncommerce_pmotherapi_setConfig ($args)
{
  pnModSetVar ('pncommerce', 'pmotherData',serialize($args));
}


/**
 * This function is used during the checkout process
 * it's called after the checkout where the user agrees to
 * buy the items, so you can do the rest here to finish the
 * payment process if possible. otherwise just redirect to the next step
 * called processshippingfinal
 * don't forget to bypass all important informations 
 * like ON,KID,maxStep
 * it's important when the user jumps back to earlier steps
 *
 * @param $args['KID'] string CustomerID
 * @param $args['ON']  string ordernumber
 */
function pncommerce_pmotherapi_processpayment ($args)
{
	// no need to ask for anything, just forward
	pnRedirect( pnModURL( 'pncommerce', 'user', 'processshippingfinal' ) );
	return true;
}
/**
 * This function is used during the checkout process
 * you can let the user provide special information
 * you need for further processing
 * when you don't need any info just redirect the user to
 * getshippingmethod in the pnuser.php
 * don't forget to bypass all important informations 
 * like BPM,BSM,KID,maxStep
 * it's important when the user jumps back to earlier steps
 *
 * It's important to redirect to getshippingmethod if everything was ok here
 *
 */
function pncommerce_pmotherapi_getdata ($args)
// $BPM
{
	// no need to ak for anything, just forward
	pnRedirect( pnModURL( 'pncommerce', 'user', 'getshippingmethod' ) );
	return true;
}

function pncommerce_pmotherapi_getdataresponse($args)
// 
{
}
function pncommerce_pmotherapi_userinsert($args)
{
}

function pncommerce_pmotherapi_order ($args)
{
}

function pncommerce_pmotherapi_configintro()
{
   	$Mode = pnVarCleanFromInput ('Mode');
    if( !pnModAPILoad( 'pncommerce', 'user' ) )
    {
        return false;
    }
	if (pnSecAuthAction(0, '::', '::', ACCESS_ADMIN))
	{
        switch( $Mode )
        {
	    case 'install':
    		$default=array('PMCalcFunc'=>'PMCFlat',
	    		            'PMCFlatPrice' =>0);
		    pncommerce_pmotherapi_setConfig($default);
		    pnModSetVar ('pncommerce', 'pmother', 'on');
	        break;
	    case 'remove':
    		pncommerce_pmotherapi_quietremove();
	        break;
	    case 'activate':
		    pnModSetVar ('pncommerce', 'pmother', 'on');
	        break;
	    case 'deactivate':
		    pnModSetVar ('pncommerce', 'pmother', 'off');
	        break;
	    default:
            break;
	    }
       	pnRedirect( pnModAPIFunc('pncommerce','user','pncModURL',
								array('Module'=>'pncommerce', 'Section'=> 'admin', 'Function'=>'paymethodconfig')));
        return true;
    }
	else
	{
		return showerrorpage( _PNC_NOAUTH, __FILE__, __LINE__ );
	}
}

function pncommerce_pmotherapi_showoption($args)
{
	extract ($args);
	$temp ="<input type='radio' name='PayMethod' value='pmother'";
	if ( $BPM == 'pmother' )
	{
		$temp .= " checked ";
	}
	$temp .= ">"._PNC_OTHERORDER."<br>";
	return $temp;
}

function pncommerce_pmotherapi_info ()
{
	return (_PNC_OTHERORDER);
}

function pncommerce_pmotherapi_footermsg ($args)
// $ON
{
	extract ($args);
	return (""._PNC_WEWILLCONTACTYOU."<br>");
}

function pncommerce_pmotherapi_quietremove ()
{
	pnModDelVar ('pncommerce', 'pmother');	
	pnModDelVar('pncommerce','pmotherdata');
}

/**
 * This function is used during the checkout process
 * You can calculate a fee for the selected paymethod here
 *
 * @param $args['SubTotal'] Double the total costs with shipping included
 * @return double 
 * @returns the fee for this paymethod
 */
function pncommerce_pmotherapi_getPaymethodTotal($args)
{
//Return 0 = this Paymethod is for free
	if (!pnModAPILoad('pncommerce', 'user'))
      {
        return showerrorpage("unable to load pnuserapi", __FILE__, __LINE__);
      }
	$config=pncommerce_pmotherapi_getConfig();
	//add value to array to make the function able to calculate the fee
	$config['Value']=$args['SubTotal'];
	return pnModAPIFunc('pncommerce','user','getPMCalcValue',$config);
}

/**
 * Asks for special data for this paymethod, for example minimum fee or default fee, ...
 * Account numbers, ...
 * ****
 * You have to redirect to 'paymethodconfig' when you're done
 * ****
 * @return String 
 * @returns the config page for this paymethod
 */
function pncommerce_pmotherapi_config($args)
{
	if (!pnModAPILoad('pncommerce', 'user'))
    {
        return showerrorpage("unable to load pnuserapi", __FILE__, __LINE__);
    }

	if (pnSecAuthAction(0, '::', '::', ACCESS_ADMIN))
	{
	    $Submit = pnVarCleanFromInput( 'Submit' );
	    if( !$Submit )
	    {
	        $smarty = new pnRender();
            $smarty->caching = false;
	        $smarty->assign( 'config', pncommerce_pmotherapi_getConfig() );
	        return $smarty->fetch( 'pncommerce_pmother_configuration.html' );
	    }
	    else // submit is set
	    {
    
    $authid = pnVarCleanFromInput( 'authid' ); 
    if( !pnSecConfirmAuthKey( $authid ) ) 
    { 
        return showerrorpage( _PNC_BADAUTHKEY, __FILE__, __LINE__ ); 
    }     
    
    		$storage=array();
    		$storage['PMCalcFunc'] = pnVarCleanFromInput('PMCalcFunc');
    		$storage=pnModAPIFunc('pncommerce','user','gatherPMCalcData',$storage);
    		$config=pncommerce_pmotherapi_setConfig($storage);
    		pnRedirect( pnModAPIFunc('pncommerce','user','pncModURL',
    								array('Module'=>'pncommerce', 'Section'=> 'admin', 'Function'=>'paymethodconfig')));
    		return true; 
	    }
	    
	}
	return false;
}

?>
